/*
 * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ({

/***/ "./kankan.js":
/*!*******************!*\
  !*** ./kankan.js ***!
  \*******************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   kankan: () => (/* binding */ kankan)\n/* harmony export */ });\n// 检查更新->获取清单->获取本地清单->对比清单->根据清单下载脚本->注册脚本\r\nvar kankan = {\r\n    manifestUrl: \"\", // 清单链接\r\n    // 检查更新\r\n    checkUpdate() {\r\n\r\n    },\r\n    // 获取清单\r\n    getManifest() {\r\n\r\n    },\r\n    //获取本地清单列表\r\n    getLocalManifest() {\r\n\r\n    },\r\n    // 下载并覆盖本地需要更新的script\r\n    download(url) {\r\n\r\n    },\r\n    // 重新注册脚本\r\n    registerContentScript() {\r\n\r\n    }\r\n};\r\n\r\n\n\n//# sourceURL=webpack:///./kankan.js?");

/***/ }),

/***/ "./main.js":
/*!*****************!*\
  !*** ./main.js ***!
  \*****************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _kankan__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./kankan */ \"./kankan.js\");\n/* harmony import */ var _plugin_manager__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./plugin_manager */ \"./plugin_manager.js\");\n\r\n\r\n\r\nvar onMessageListener = function(message, sender, cb) {\r\n    switch(message.action) {\r\n        case \"getSearchPlugins\":\r\n            console.log(_plugin_manager__WEBPACK_IMPORTED_MODULE_1__.PluginManager._plugins);\r\n            cb({\r\n                tabId: sender.tab.id,\r\n                plugins: _plugin_manager__WEBPACK_IMPORTED_MODULE_1__.PluginManager._plugins,\r\n                pluginInterfaces: _plugin_manager__WEBPACK_IMPORTED_MODULE_1__.PluginManager._pluginInterfaces\r\n            });\r\n            break;\r\n    }\r\n}\r\nvar installed = function({reason}) {\r\n    if (reason == chrome.runtime.OnInstalledReason.INSTALL) {\r\n        console.info(\"installed\");\r\n    }\r\n    _kankan__WEBPACK_IMPORTED_MODULE_0__.kankan.registerContentScript();\r\n    pluginManager.init();\r\n};\r\nfunction main() {\r\n    chrome.runtime.onInstalled.addListener(installed);\r\n    chrome.runtime.onMessage.addListener(onMessageListener);\r\n}\r\n\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (main());\n\n//# sourceURL=webpack:///./main.js?");

/***/ }),

/***/ "./plugin_manager.js":
/*!***************************!*\
  !*** ./plugin_manager.js ***!
  \***************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   PluginManager: () => (/* binding */ PluginManager)\n/* harmony export */ });\n/* harmony import */ var _tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tools */ \"./tools.js\");\n\r\n\r\nvar PluginManager = {\r\n    initialized: false,\r\n    _pluginInterfaces: [],\r\n    _plugins: [],\r\n    _manifests: [],\r\n    exec: async function () {\r\n        if (!PluginManager.initialized) {\r\n            console.log(\"Waiting for initialization\");\r\n            setTimeout(PluginManager.exec, 1);\r\n        } else {\r\n\r\n            var checkRule = async (pattern) => {\r\n                return currentTab().then(tab => {\r\n                    console.log(tab.url);\r\n                    return pattern.test(tab.url);\r\n                })\r\n                return pattern.test();\r\n            }\r\n            var execPlugin = ({class_name: cn, matches: matches, js: js}) => {\r\n                console.log(cn, matches, js);\r\n                chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {\r\n                    console.log(tabs[0].id);\r\n                    (0,_tools__WEBPACK_IMPORTED_MODULE_0__.execScript)(tabs[0].id, script);\r\n                });\r\n            }\r\n            PluginManager._plugins.forEach(execPlugin)\r\n        }\r\n    },\r\n\r\n    init: async function () {\r\n        var readFile = async function (file) {\r\n            var content = \"\";\r\n            var url = chrome.runtime.getURL(file);\r\n            try {\r\n                content = await fetch(url).then(function (response) {\r\n                    if (response.ok && response.status === 200) {\r\n                        return response.text();\r\n                    } else throw new Error(`status: ${response.status}`);\r\n                }).catch(function (err) {\r\n                    console.log(err);\r\n                    return \"\"\r\n                })\r\n            } catch (e) {\r\n                console.log(\"getRawContent \" + e);\r\n            }\r\n            return content;\r\n        };\r\n        var loadManifest = async function (file) {\r\n            return readFile(file)\r\n                .then(res => JSON.parse(res))\r\n                .catch((err) => {\r\n                    console.log(\"loadManifest error\", err);\r\n                    return null;\r\n                });\r\n        }\r\n        var manifest = await loadManifest(\"assets/plugins/manifest.json\");\r\n        PluginManager._manifests = manifest.manifests;\r\n        PluginManager._pluginInterfaces.push(...manifest.plugins);\r\n        for (var file of manifest.manifests) {\r\n            await loadManifest(file).then(res => {\r\n                for (var a in res.plugins) {\r\n                    for (var b in res.plugins[a].js) {\r\n                        res.plugins[a].js[b] = chrome.runtime.getURL(res.plugins[a].js[b]);\r\n                    }\r\n                }\r\n                PluginManager._plugins.push(...res.plugins);\r\n            });\r\n        }\r\n        PluginManager.initialized = true;\r\n        // console.log(plugins);\r\n    }\r\n};\r\n\n\n//# sourceURL=webpack:///./plugin_manager.js?");

/***/ }),

/***/ "./tools.js":
/*!******************!*\
  !*** ./tools.js ***!
  \******************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   execScript: () => (/* binding */ execScript),\n/* harmony export */   getCurrentTab: () => (/* binding */ getCurrentTab),\n/* harmony export */   readFile: () => (/* binding */ readFile)\n/* harmony export */ });\nfunction readFile() {\r\n\r\n}\r\n\r\nfunction execScript(tabId, script) {\r\n    chrome.scripting.executeScript({\r\n        target: {tabId: tabId},\r\n        func: script,\r\n    });\r\n}\r\n\r\nconst getCurrentTab = () => new Promise((resolve, reject) => {\r\n    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {\r\n        var currentTab = tabs[0];\r\n        if (currentTab) {\r\n            resolve(currentTab);\r\n        } else {\r\n            reject(\"false\");\r\n        }\r\n    });\r\n});\n\n//# sourceURL=webpack:///./tools.js?");

/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/define property getters */
/******/ 	(() => {
/******/ 		// define getter functions for harmony exports
/******/ 		__webpack_require__.d = (exports, definition) => {
/******/ 			for(var key in definition) {
/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ 				}
/******/ 			}
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
/******/ 	(() => {
/******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/make namespace object */
/******/ 	(() => {
/******/ 		// define __esModule on exports
/******/ 		__webpack_require__.r = (exports) => {
/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 			}
/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
/******/ 		};
/******/ 	})();
/******/ 	
/************************************************************************/
/******/ 	
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	// This entry module can't be inlined because the eval devtool is used.
/******/ 	var __webpack_exports__ = __webpack_require__("./main.js");
/******/ 	
/******/ })()
;